package gstruct.cli;

import static org.junit.Assert.*;

import java.util.Properties;

import gstruct.cli.CLIArgument;
import gstruct.cli.ParseResult;

public final class CLIArgUtils {
	private CLIArgUtils() { }
	
	public static void assertRequired(CLIArgument<? super Properties> arg, boolean b) {
		if (b) {
			assertTrue("Argument " + arg + " should be required",
					arg.isRequired());
		} else {
			assertFalse("Argument " + arg + " should not be required",
					arg.isRequired());
		}
	}
	
	public static void assertRequired(CLIArgument<? super Properties> arg) {
		assertRequired(arg, true);
	}

	public static void assertNotRequired(CLIArgument<? super Properties> arg) {
		assertRequired(arg, false);
	}
	
	public static void assertUnique(CLIArgument<? super Properties> arg, boolean b) {
		if (b) {
			assertTrue("Argument " + arg + " should be unique",
					arg.isUnique());
		} else {
			assertFalse("Argument " + arg + " should not be unique",
					arg.isUnique());
		}
	}
	
	public static void assertUnique(CLIArgument<? super Properties> arg) {
		assertUnique(arg, true);
	}

	public static void assertNotUnique(CLIArgument<? super Properties> arg) {
		assertUnique(arg, false);
	}

	public static void assertDescription(CLIArgument<? super Properties> arg, String desc) {
		assertEquals("Descriptions do not match", desc, arg.getDescription());
	}

	public static void assertMatcher(CLIArgument<? super Properties> arg, String m) {
		assertEquals("Matchers do not match", m, arg.matcher());
	}
	
	public static void assertName(CLIArgument<? super Properties> arg, String name) {
		assertEquals("Names do not match", name, arg.getName());
	}
	
	public static void assertResultEmpty(ParseResult<?> res) {
		assertTrue(res.getArguments().isEmpty());
		assertTrue(res.getErrors().isEmpty());
	}
	
	public static void assertPropResultEmpty(ParseResult<Properties> res) {
		assertTrue(res.getArguments().isEmpty());
		assertTrue(res.getResult().isEmpty());
		assertTrue(res.getErrors().isEmpty());
	}
	
	public static <T> void addArgument(ParseResult<T> res, CLIArgument<? super T> arg) {
		res.addArgument(arg);
	}
}
